home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / gdb / gdb.i4 < prev    next >
Encoding:
GNU Info File  |  1994-07-26  |  49.8 KB  |  1,369 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input
  2. file gdb.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb::                         The GNU debugger.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU debugger GDB.
  8.  
  9.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  10. Source-Level Debugger' for GDB Version 4.12.
  11.  
  12.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  13. Foundation, Inc.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided also
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions.
  27.  
  28. 
  29. File: gdb.info,  Node: Print Settings,  Next: Value History,  Prev: Auto Display,  Up: Data
  30.  
  31. Print settings
  32. ==============
  33.  
  34.    GDB provides the following ways to control how arrays, structures,
  35. and symbols are printed.
  36.  
  37. These settings are useful for debugging programs in any language:
  38.  
  39. `set print address'
  40. `set print address on'
  41.      GDB prints memory addresses showing the location of stack traces,
  42.      structure values, pointer values, breakpoints, and so forth, even
  43.      when it also displays the contents of those addresses.  The default
  44.      is `on'.  For example, this is what a stack frame display looks
  45.      like, with `set print address on':
  46.  
  47.           (gdb) f
  48.           #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
  49.               at input.c:530
  50.           530         if (lquote != def_lquote)
  51.  
  52. `set print address off'
  53.      Do not print addresses when displaying their contents.  For
  54.      example, this is the same stack frame displayed with `set print
  55.      address off':
  56.  
  57.           (gdb) set print addr off
  58.           (gdb) f
  59.           #0  set_quotes (lq="<<", rq=">>") at input.c:530
  60.           530         if (lquote != def_lquote)
  61.  
  62.      You can use `set print address off' to eliminate all machine
  63.      dependent displays from the GDB interface.  For example, with
  64.      `print address off', you should get the same text for backtraces on
  65.      all machines--whether or not they involve pointer arguments.
  66.  
  67. `show print address'
  68.      Show whether or not addresses are to be printed.
  69.  
  70.    When GDB prints a symbolic address, it normally prints the closest
  71. earlier symbol plus an offset.  If that symbol does not uniquely
  72. identify the address (for example, it is a name whose scope is a single
  73. source file), you may need to disambiguate.  One way to do this is with
  74. `info line', for example `info line *0x4537'.  Alternately, you can set
  75. GDB to print the source file and line number when it prints a symbolic
  76. address:
  77.  
  78. `set print symbol-filename on'
  79.      Tell GDB to print the source file name and line number of a symbol
  80.      in the symbolic form of an address.
  81.  
  82. `set print symbol-filename off'
  83.      Do not print source file name and line number of a symbol.  This
  84.      is the default.
  85.  
  86. `show print symbol-filename'
  87.      Show whether or not GDB will print the source file name and line
  88.      number of a symbol in the symbolic form of an address.
  89.  
  90.    Another situation where it is helpful to show symbol filenames and
  91. line numbers is when disassembling code; GDB shows you the line number
  92. and source file that corresponds to each instruction.
  93.  
  94.    Also, you may wish to see the symbolic form only if the address being
  95. printed is reasonably close to the closest earlier symbol:
  96.  
  97. `set print max-symbolic-offset MAX-OFFSET'
  98.      Tell GDB to only display the symbolic form of an address if the
  99.      offset between the closest earlier symbol and the address is less
  100.      than MAX-OFFSET.  The default is 0, which means to always print the
  101.      symbolic form of an address, if any symbol precedes it.
  102.  
  103. `show print max-symbolic-offset'
  104.      Ask how large the maximum offset is that GDB prints in a symbolic
  105.      address.
  106.  
  107.    Sometimes GDB can tell you more about an address if it does an
  108. extensive search of its symbol information.  The default is to provide
  109. a quick symbolic display that is usually correct, but which may not give
  110. the most useful answer when working in some object file formats.  If
  111. you are not getting the information you need, try:
  112.  
  113. `set print fast-symbolic-addr off'
  114.      Search all symbol information when displaying an address
  115.      symbolically.  This setting may display more information about
  116.      static variables, for example, but also takes longer.
  117.  
  118. `set print fast-symbolic-addr'
  119. `set print fast-symbolic-addr on'
  120.      Search only the "minimal symbol information" when displaying
  121.      symbolic information about an address.  This is the default.
  122.  
  123. `show print fast-symbolic-addr'
  124.      Ask whether GDB is using a fast or slow method of printing
  125.      symbolic address.
  126.  
  127.    If you have a pointer and you are not sure where it points, try `set
  128. print symbol-filename on' and `set print fast-symbolic-addr off'.  Then
  129. you can determine the name and source file location of the variable
  130. where it points, using `p/a POINTER'.  This interprets the address in
  131. symbolic form.  For example, here GDB shows that a variable `ptt'
  132. points at another variable `t', defined in `hi2.c':
  133.  
  134.      (gdb) set print fast-symbolic-addr off
  135.      (gdb) set print symbol-filename on
  136.      (gdb) p/a ptt
  137.      $4 = 0xe008 <t in hi2.c>
  138.  
  139.      *Warning:* For pointers that point to a local variable, `p/a' does
  140.      not show the symbol name and filename of the referent, even with
  141.      the appropriate `set print' options turned on.
  142.  
  143.    Other settings control how different kinds of objects are printed:
  144.  
  145. `set print array'
  146. `set print array on'
  147.      Pretty-print arrays.  This format is more convenient to read, but
  148.      uses more space.  The default is off.
  149.  
  150. `set print array off'
  151.      Return to compressed format for arrays.
  152.  
  153. `show print array'
  154.      Show whether compressed or pretty format is selected for displaying
  155.      arrays.
  156.  
  157. `set print elements NUMBER-OF-ELEMENTS'
  158.      If GDB is printing a large array, it stops printing after it has
  159.      printed the number of elements set by the `set print elements'
  160.      command.  This limit also applies to the display of strings.
  161.      Setting the number of elements to zero means that the printing is
  162.      unlimited.
  163.  
  164. `show print elements'
  165.      Display the number of elements of a large array that GDB prints
  166.      before losing patience.
  167.  
  168. `set print pretty on'
  169.      Cause GDB to print structures in an indented format with one
  170.      member per line, like this:
  171.  
  172.           $1 = {
  173.             next = 0x0,
  174.             flags = {
  175.               sweet = 1,
  176.               sour = 1
  177.             },
  178.             meat = 0x54 "Pork"
  179.           }
  180.  
  181. `set print pretty off'
  182.      Cause GDB to print structures in a compact format, like this:
  183.  
  184.           $1 = {next = 0x0, flags = {sweet = 1, sour = 1}, \
  185.           meat = 0x54 "Pork"}
  186.  
  187.      This is the default format.
  188.  
  189. `show print pretty'
  190.      Show which format GDB is using to print structures.
  191.  
  192. `set print sevenbit-strings on'
  193.      Print using only seven-bit characters; if this option is set, GDB
  194.      displays any eight-bit characters (in strings or character values)
  195.      using the notation `\'NNN.  This setting is best if you are
  196.      working in English (ASCII) and you use the high-order bit of
  197.      characters as a marker or "meta" bit.
  198.  
  199. `set print sevenbit-strings off'
  200.      Print full eight-bit characters.  This allows the use of more
  201.      international character sets, and is the default.
  202.  
  203. `show print sevenbit-strings'
  204.      Show whether or not GDB is printing only seven-bit characters.
  205.  
  206. `set print union on'
  207.      Tell GDB to print unions which are contained in structures.  This
  208.      is the default setting.
  209.  
  210. `set print union off'
  211.      Tell GDB not to print unions which are contained in structures.
  212.  
  213. `show print union'
  214.      Ask GDB whether or not it will print unions which are contained in
  215.      structures.
  216.  
  217.      For example, given the declarations
  218.  
  219.           typedef enum {Tree, Bug} Species;
  220.           typedef enum {Big_tree, Acorn, Seedling} Tree_forms;
  221.           typedef enum {Caterpillar, Cocoon, Butterfly}
  222.                         Bug_forms;
  223.           
  224.           struct thing {
  225.             Species it;
  226.             union {
  227.               Tree_forms tree;
  228.               Bug_forms bug;
  229.             } form;
  230.           };
  231.           
  232.           struct thing foo = {Tree, {Acorn}};
  233.  
  234.      with `set print union on' in effect `p foo' would print
  235.  
  236.           $1 = {it = Tree, form = {tree = Acorn, bug = Cocoon}}
  237.  
  238.      and with `set print union off' in effect it would print
  239.  
  240.           $1 = {it = Tree, form = {...}}
  241.  
  242. These settings are of interest when debugging C++ programs:
  243.  
  244. `set print demangle'
  245. `set print demangle on'
  246.      Print C++ names in their source form rather than in the encoded
  247.      ("mangled") form passed to the assembler and linker for type-safe
  248.      linkage.  The default is `on'.
  249.  
  250. `show print demangle'
  251.      Show whether C++ names are printed in mangled or demangled form.
  252.  
  253. `set print asm-demangle'
  254. `set print asm-demangle on'
  255.      Print C++ names in their source form rather than their mangled
  256.      form, even in assembler code printouts such as instruction
  257.      disassemblies.  The default is off.
  258.  
  259. `show print asm-demangle'
  260.      Show whether C++ names in assembly listings are printed in mangled
  261.      or demangled form.
  262.  
  263. `set demangle-style STYLE'
  264.      Choose among several encoding schemes used by different compilers
  265.      to represent C++ names.  The choices for STYLE are currently:
  266.  
  267.     `auto'
  268.           Allow GDB to choose a decoding style by inspecting your
  269.           program.
  270.  
  271.     `gnu'
  272.           Decode based on the GNU C++ compiler (`g++') encoding
  273.           algorithm.
  274.  
  275.     `lucid'
  276.           Decode based on the Lucid C++ compiler (`lcc') encoding
  277.           algorithm.
  278.  
  279.     `arm'
  280.           Decode using the algorithm in the `C++ Annotated Reference
  281.           Manual'.  *Warning:* this setting alone is not sufficient to
  282.           allow debugging `cfront'-generated executables.  GDB would
  283.           require further enhancement to permit that.
  284.  
  285. `show demangle-style'
  286.      Display the encoding style currently in use for decoding C++
  287.      symbols.
  288.  
  289. `set print object'
  290. `set print object on'
  291.      When displaying a pointer to an object, identify the *actual*
  292.      (derived) type of the object rather than the *declared* type, using
  293.      the virtual function table.
  294.  
  295. `set print object off'
  296.      Display only the declared type of objects, without reference to the
  297.      virtual function table.  This is the default setting.
  298.  
  299. `show print object'
  300.      Show whether actual, or declared, object types are displayed.
  301.  
  302. `set print vtbl'
  303. `set print vtbl on'
  304.      Pretty print C++ virtual function tables.  The default is off.
  305.  
  306. `set print vtbl off'
  307.      Do not pretty print C++ virtual function tables.
  308.  
  309. `show print vtbl'
  310.      Show whether C++ virtual function tables are pretty printed, or
  311.      not.
  312.  
  313. 
  314. File: gdb.info,  Node: Value History,  Next: Convenience Vars,  Prev: Print Settings,  Up: Data
  315.  
  316. Value history
  317. =============
  318.  
  319.    Values printed by the `print' command are saved in the GDB "value
  320. history" so that you can refer to them in other expressions.  Values are
  321. kept until the symbol table is re-read or discarded (for example with
  322. the `file' or `symbol-file' commands).  When the symbol table changes,
  323. the value history is discarded, since the values may contain pointers
  324. back to the types defined in the symbol table.
  325.  
  326.    The values printed are given "history numbers" by which you can
  327. refer to them.  These are successive integers starting with one.
  328. `print' shows you the history number assigned to a value by printing
  329. `$NUM = ' before the value; here NUM is the history number.
  330.  
  331.    To refer to any previous value, use `$' followed by the value's
  332. history number.  The way `print' labels its output is designed to
  333. remind you of this.  Just `$' refers to the most recent value in the
  334. history, and `$$' refers to the value before that.  `$$N' refers to the
  335. Nth value from the end; `$$2' is the value just prior to `$$', `$$1' is
  336. equivalent to `$$', and `$$0' is equivalent to `$'.
  337.  
  338.    For example, suppose you have just printed a pointer to a structure
  339. and want to see the contents of the structure.  It suffices to type
  340.  
  341.      p *$
  342.  
  343.    If you have a chain of structures where the component `next' points
  344. to the next one, you can print the contents of the next one with this:
  345.  
  346.      p *$.next
  347.  
  348. You can print successive links in the chain by repeating this
  349. command--which you can do by just typing RET.
  350.  
  351.    Note that the history records values, not expressions.  If the value
  352. of `x' is 4 and you type these commands:
  353.  
  354.      print x
  355.      set x=5
  356.  
  357. then the value recorded in the value history by the `print' command
  358. remains 4 even though the value of `x' has changed.
  359.  
  360. `show values'
  361.      Print the last ten values in the value history, with their item
  362.      numbers.  This is like `p $$9' repeated ten times, except that
  363.      `show values' does not change the history.
  364.  
  365. `show values N'
  366.      Print ten history values centered on history item number N.
  367.  
  368. `show values +'
  369.      Print ten history values just after the values last printed.  If
  370.      no more values are available, produces no display.
  371.  
  372.    Pressing RET to repeat `show values N' has exactly the same effect
  373. as `show values +'.
  374.  
  375. 
  376. File: gdb.info,  Node: Convenience Vars,  Next: Registers,  Prev: Value History,  Up: Data
  377.  
  378. Convenience variables
  379. =====================
  380.  
  381.    GDB provides "convenience variables" that you can use within GDB to
  382. hold on to a value and refer to it later.  These variables exist
  383. entirely within GDB; they are not part of your program, and setting a
  384. convenience variable has no direct effect on further execution of your
  385. program.  That is why you can use them freely.
  386.  
  387.    Convenience variables are prefixed with `$'.  Any name preceded by
  388. `$' can be used for a convenience variable, unless it is one of the
  389. predefined machine-specific register names (*note Registers::.).
  390. (Value history references, in contrast, are *numbers* preceded by `$'.
  391. *Note Value history: Value History.)
  392.  
  393.    You can save a value in a convenience variable with an assignment
  394. expression, just as you would set a variable in your program.  For
  395. example:
  396.  
  397.      set $foo = *object_ptr
  398.  
  399. would save in `$foo' the value contained in the object pointed to by
  400. `object_ptr'.
  401.  
  402.    Using a convenience variable for the first time creates it, but its
  403. value is `void' until you assign a new value.  You can alter the value
  404. with another assignment at any time.
  405.  
  406.    Convenience variables have no fixed types.  You can assign a
  407. convenience variable any type of value, including structures and
  408. arrays, even if that variable already has a value of a different type.
  409. The convenience variable, when used as an expression, has the type of
  410. its current value.
  411.  
  412. `show convenience'
  413.      Print a list of convenience variables used so far, and their
  414.      values.  Abbreviated `show con'.
  415.  
  416.    One of the ways to use a convenience variable is as a counter to be
  417. incremented or a pointer to be advanced.  For example, to print a field
  418. from successive elements of an array of structures:
  419.  
  420.      set $i = 0
  421.      print bar[$i++]->contents
  422.      ... repeat that command by typing RET.
  423.  
  424.    Some convenience variables are created automatically by GDB and given
  425. values likely to be useful.
  426.  
  427. `$_'
  428.      The variable `$_' is automatically set by the `x' command to the
  429.      last address examined (*note Examining memory: Memory.).  Other
  430.      commands which provide a default address for `x' to examine also
  431.      set `$_' to that address; these commands include `info line' and
  432.      `info breakpoint'.  The type of `$_' is `void *' except when set
  433.      by the `x' command, in which case it is a pointer to the type of
  434.      `$__'.
  435.  
  436. `$__'
  437.      The variable `$__' is automatically set by the `x' command to the
  438.      value found in the last address examined.  Its type is chosen to
  439.      match the format in which the data was printed.
  440.  
  441. 
  442. File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
  443.  
  444. Registers
  445. =========
  446.  
  447.    You can refer to machine register contents, in expressions, as
  448. variables with names starting with `$'.  The names of registers are
  449. different for each machine; use `info registers' to see the names used
  450. on your machine.
  451.  
  452. `info registers'
  453.      Print the names and values of all registers except floating-point
  454.      registers (in the selected stack frame).
  455.  
  456. `info all-registers'
  457.      Print the names and values of all registers, including
  458.      floating-point registers.
  459.  
  460. `info registers REGNAME ...'
  461.      Print the relativized value of each specified register REGNAME.
  462.      rEGNAME may be any register name valid on the machine you are
  463.      using, with or without the initial `$'.
  464.  
  465.    GDB has four "standard" register names that are available (in
  466. expressions) on most machines--whenever they do not conflict with an
  467. architecture's canonical mnemonics for registers.  The register names
  468. `$pc' and `$sp' are used for the program counter register and the stack
  469. pointer.  `$fp' is used for a register that contains a pointer to the
  470. current stack frame, and `$ps' is used for a register that contains the
  471. processor status.  For example, you could print the program counter in
  472. hex with
  473.  
  474.      p/x $pc
  475.  
  476. or print the instruction to be executed next with
  477.  
  478.      x/i $pc
  479.  
  480. or add four to the stack pointer(1) with
  481.  
  482.      set $sp += 4
  483.  
  484.    Whenever possible, these four standard register names are available
  485. on your machine even though the machine has different canonical
  486. mnemonics, so long as there is no conflict.  The `info registers'
  487. command shows the canonical names.  For example, on the SPARC, `info
  488. registers' displays the processor status register as `$psr' but you can
  489. also refer to it as `$ps'.
  490.  
  491.    GDB always considers the contents of an ordinary register as an
  492. integer when the register is examined in this way.  Some machines have
  493. special registers which can hold nothing but floating point; these
  494. registers are considered to have floating point values.  There is no way
  495. to refer to the contents of an ordinary register as floating point value
  496. (although you can *print* it as a floating point value with `print/f
  497. $REGNAME').
  498.  
  499.    Some registers have distinct "raw" and "virtual" data formats.  This
  500. means that the data format in which the register contents are saved by
  501. the operating system is not the same one that your program normally
  502. sees.  For example, the registers of the 68881 floating point
  503. coprocessor are always saved in "extended" (raw) format, but all C
  504. programs expect to work with "double" (virtual) format.  In such cases,
  505. GDB normally works with the virtual format only (the format that makes
  506. sense for your program), but the `info registers' command prints the
  507. data in both formats.
  508.  
  509.    Normally, register values are relative to the selected stack frame
  510. (*note Selecting a frame: Selection.).  This means that you get the
  511. value that the register would contain if all stack frames farther in
  512. were exited and their saved registers restored.  In order to see the
  513. true contents of hardware registers, you must select the innermost
  514. frame (with `frame 0').
  515.  
  516.    However, GDB must deduce where registers are saved, from the machine
  517. code generated by your compiler.  If some registers are not saved, or if
  518. GDB is unable to locate the saved registers, the selected stack frame
  519. makes no difference.
  520.  
  521. `set rstack_high_address ADDRESS'
  522.      On AMD 29000 family processors, registers are saved in a separate
  523.      "register stack".  There is no way for GDB to determine the extent
  524.      of this stack.  Normally, GDB just assumes that the stack is "large
  525.      enough".  This may result in GDB referencing memory locations that
  526.      do not exist.  If necessary, you can get around this problem by
  527.      specifying the ending address of the register stack with the `set
  528.      rstack_high_address' command.  The argument should be an address,
  529.      which you probably want to precede with `0x' to specify in
  530.      hexadecimal.
  531.  
  532. `show rstack_high_address'
  533.      Display the current limit of the register stack, on AMD 29000
  534.      family processors.
  535.  
  536.    ---------- Footnotes ----------
  537.  
  538.    (1)  This is a way of removing one word from the stack, on machines
  539. where stacks grow downward in memory (most machines, nowadays).  This
  540. assumes that the innermost stack frame is selected; setting `$sp' is
  541. not allowed when other stack frames are selected.  To pop entire frames
  542. off the stack, regardless of machine architecture, use `return'; *note
  543. Returning from a function: Returning..
  544.  
  545. 
  546. File: gdb.info,  Node: Floating Point Hardware,  Prev: Registers,  Up: Data
  547.  
  548. Floating point hardware
  549. =======================
  550.  
  551.    Depending on the host machine architecture, GDB may be able to give
  552. you more information about the status of the floating point hardware.
  553.  
  554. `info float'
  555.      Display hardware-dependent information about the floating point
  556.      unit.  The exact contents and layout vary depending on the
  557.      floating point chip; on some platforms, `info float' is not
  558.      available at all.
  559.  
  560. 
  561. File: gdb.info,  Node: Languages,  Next: Symbols,  Prev: Data,  Up: Top
  562.  
  563. Using GDB with Different Languages
  564. **********************************
  565.  
  566.    Although programming languages generally have common aspects, they
  567. are rarely expressed in the same manner.  For instance, in ANSI C,
  568. dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
  569. it is accomplished by `p^'.  Values can also be represented (and
  570. displayed) differently.  Hex numbers in C are written like `0x1ae',
  571. while in Modula-2 they appear as `1AEH'.
  572.  
  573.    Language-specific information is built into GDB for some languages,
  574. allowing you to express operations like the above in your program's
  575. native language, and allowing GDB to output values in a manner
  576. consistent with the syntax of your program's native language.  The
  577. language you use to build expressions, called the "working language",
  578. can be selected manually, or GDB can set it automatically.
  579.  
  580. * Menu:
  581.  
  582. * Setting::                     Switching between source languages
  583. * Show::                        Displaying the language
  584.  
  585. * Checks::                      Type and range checks
  586.  
  587. * Support::                     Supported languages
  588.  
  589. 
  590. File: gdb.info,  Node: Setting,  Next: Show,  Up: Languages
  591.  
  592. Switching between source languages
  593. ==================================
  594.  
  595.    There are two ways to control the working language--either have GDB
  596. set it automatically, or select it manually yourself.  You can use the
  597. `set language' command for either purpose.  On startup, GDB defaults to
  598. setting the language automatically.
  599.  
  600. * Menu:
  601.  
  602. * Manually::                    Setting the working language manually
  603. * Automatically::               Having GDB infer the source language
  604.  
  605. 
  606. File: gdb.info,  Node: Manually,  Next: Automatically,  Up: Setting
  607.  
  608. Setting the working language
  609. ----------------------------
  610.  
  611.    If you allow GDB to set the language automatically, expressions are
  612. interpreted the same way in your debugging session and your program.
  613.  
  614.    If you wish, you may set the language manually.  To do this, issue
  615. the command `set language LANG', where LANG is the name of a language,
  616. such as `c' or `modula-2'.  For a list of the supported languages, type
  617. `set language'.
  618.  
  619.    Setting the language manually prevents GDB from updating the working
  620. language automatically.  This can lead to confusion if you try to debug
  621. a program when the working language is not the same as the source
  622. language, when an expression is acceptable to both languages--but means
  623. different things.  For instance, if the current source file were
  624. written in C, and GDB was parsing Modula-2, a command such as:
  625.  
  626.      print a = b + c
  627.  
  628. might not have the effect you intended.  In C, this means to add `b'
  629. and `c' and place the result in `a'.  The result printed would be the
  630. value of `a'.  In Modula-2, this means to compare `a' to the result of
  631. `b+c', yielding a `BOOLEAN' value.
  632.  
  633. 
  634. File: gdb.info,  Node: Automatically,  Prev: Manually,  Up: Setting
  635.  
  636. Having GDB infer the source language
  637. ------------------------------------
  638.  
  639.    To have GDB set the working language automatically, use `set
  640. language local' or `set language auto'.  GDB then infers the language
  641. that a program was written in by looking at the name of its source
  642. files, and examining their extensions:
  643.  
  644. `*.mod'
  645.      Modula-2 source file
  646.  
  647. `*.c'
  648.      C source file
  649.  
  650. `*.C'
  651. `*.cc'
  652.      C++ source file
  653.  
  654.    This information is recorded for each function or procedure in a
  655. source file.  When your program stops in a frame (usually by
  656. encountering a breakpoint), GDB sets the working language to the
  657. language recorded for the function in that frame.  If the language for
  658. a frame is unknown (that is, if the function or block corresponding to
  659. the frame was defined in a source file that does not have a recognized
  660. extension), the current working language is not changed, and GDB issues
  661. a warning.
  662.  
  663.    This may not seem necessary for most programs, which are written
  664. entirely in one source language.  However, program modules and libraries
  665. written in one source language can be used by a main program written in
  666. a different source language.  Using `set language auto' in this case
  667. frees you from having to set the working language manually.
  668.  
  669. 
  670. File: gdb.info,  Node: Show,  Next: Checks,  Prev: Setting,  Up: Languages
  671.  
  672. Displaying the language
  673. =======================
  674.  
  675.    The following commands help you find out which language is the
  676. working language, and also what language source files were written in.
  677.  
  678. `show language'
  679.      Display the current working language.  This is the language you
  680.      can use with commands such as `print' to build and compute
  681.      expressions that may involve variables in your program.
  682.  
  683. `info frame'
  684.      Among the other information listed here (*note Information about a
  685.      frame: Frame Info.) is the source language for this frame.  This
  686.      language becomes the working language if you use an identifier
  687.      from this frame.
  688.  
  689. `info source'
  690.      Among the other information listed here (*note Examining the
  691.      Symbol Table: Symbols.) is the source language of this source file.
  692.  
  693. 
  694. File: gdb.info,  Node: Checks,  Next: Support,  Prev: Show,  Up: Languages
  695.  
  696. Type and range checking
  697. =======================
  698.  
  699.      *Warning:* In this release, the GDB commands for type and range
  700.      checking are included, but they do not yet have any effect.  This
  701.      section documents the intended facilities.
  702.  
  703.    Some languages are designed to guard you against making seemingly
  704. common errors through a series of compile- and run-time checks.  These
  705. include checking the type of arguments to functions and operators, and
  706. making sure mathematical overflows are caught at run time.  Checks such
  707. as these help to ensure a program's correctness once it has been
  708. compiled by eliminating type mismatches, and providing active checks
  709. for range errors when your program is running.
  710.  
  711.    GDB can check for conditions like the above if you wish.  Although
  712. GDB does not check the statements in your program, it can check
  713. expressions entered directly into GDB for evaluation via the `print'
  714. command, for example.  As with the working language, GDB can also
  715. decide whether or not to check automatically based on your program's
  716. source language.  *Note Supported languages: Support, for the default
  717. settings of supported languages.
  718.  
  719. * Menu:
  720.  
  721. * Type Checking::               An overview of type checking
  722. * Range Checking::              An overview of range checking
  723.  
  724. 
  725. File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
  726.  
  727. An overview of type checking
  728. ----------------------------
  729.  
  730.    Some languages, such as Modula-2, are strongly typed, meaning that
  731. the arguments to operators and functions have to be of the correct type,
  732. otherwise an error occurs.  These checks prevent type mismatch errors
  733. from ever causing any run-time problems.  For example,
  734.  
  735.      1 + 2 => 3
  736. but
  737.      error--> 1 + 2.3
  738.  
  739.    The second example fails because the `CARDINAL' 1 is not
  740. type-compatible with the `REAL' 2.3.
  741.  
  742.    For expressions you use in GDB commands, you can tell the GDB type
  743. checker to skip checking; to treat any mismatches as errors and abandon
  744. the expression; or only issue warnings when type mismatches occur, but
  745. evaluate the expression anyway.  When you choose the last of these, GDB
  746. evaluates expressions like the second example above, but also issues a
  747. warning.
  748.  
  749.    Even though you may turn type checking off, other type-based reasons
  750. may prevent GDB from evaluating an expression.  For instance, GDB does
  751. not know how to add an `int' and a `struct foo'.  These particular type
  752. errors have nothing to do with the language in use, and usually arise
  753. from expressions, such as the one described above, which make little
  754. sense to evaluate anyway.
  755.  
  756.    Each language defines to what degree it is strict about type.  For
  757. instance, both Modula-2 and C require the arguments to arithmetical
  758. operators to be numbers.  In C, enumerated types and pointers can be
  759. represented as numbers, so that they are valid arguments to mathematical
  760. operators.  *Note Supported languages: Support, for further details on
  761. specific languages.
  762.  
  763.    GDB provides some additional commands for controlling the type
  764. checker:
  765.  
  766. `set check type auto'
  767.      Set type checking on or off based on the current working language.
  768.      *Note Supported languages: Support, for the default settings for
  769.      each language.
  770.  
  771. `set check type on'
  772. `set check type off'
  773.      Set type checking on or off, overriding the default setting for the
  774.      current working language.  Issue a warning if the setting does not
  775.      match the language default.  If any type mismatches occur in
  776.      evaluating an expression while typechecking is on, GDB prints a
  777.      message and aborts evaluation of the expression.
  778.  
  779. `set check type warn'
  780.      Cause the type checker to issue warnings, but to always attempt to
  781.      evaluate the expression.  Evaluating the expression may still be
  782.      impossible for other reasons.  For example, GDB cannot add numbers
  783.      and structures.
  784.  
  785. `show type'
  786.      Show the current setting of the type checker, and whether or not
  787.      GDB is setting it automatically.
  788.  
  789. 
  790. File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
  791.  
  792. An overview of range checking
  793. -----------------------------
  794.  
  795.    In some languages (such as Modula-2), it is an error to exceed the
  796. bounds of a type; this is enforced with run-time checks.  Such range
  797. checking is meant to ensure program correctness by making sure
  798. computations do not overflow, or indices on an array element access do
  799. not exceed the bounds of the array.
  800.  
  801.    For expressions you use in GDB commands, you can tell GDB to treat
  802. range errors in one of three ways: ignore them, always treat them as
  803. errors and abandon the expression, or issue warnings but evaluate the
  804. expression anyway.
  805.  
  806.    A range error can result from numerical overflow, from exceeding an
  807. array index bound, or when you type a constant that is not a member of
  808. any type.  Some languages, however, do not treat overflows as an error.
  809. In many implementations of C, mathematical overflow causes the result
  810. to "wrap around" to lower values--for example, if M is the largest
  811. integer value, and S is the smallest, then
  812.  
  813.      M + 1 => S
  814.  
  815.    This, too, is specific to individual languages, and in some cases
  816. specific to individual compilers or machines.  *Note Supported
  817. languages: Support, for further details on specific languages.
  818.  
  819.    GDB provides some additional commands for controlling the range
  820. checker:
  821.  
  822. `set check range auto'
  823.      Set range checking on or off based on the current working language.
  824.      *Note Supported languages: Support, for the default settings for
  825.      each language.
  826.  
  827. `set check range on'
  828. `set check range off'
  829.      Set range checking on or off, overriding the default setting for
  830.      the current working language.  A warning is issued if the setting
  831.      does not match the language default.  If a range error occurs,
  832.      then a message is printed and evaluation of the expression is
  833.      aborted.
  834.  
  835. `set check range warn'
  836.      Output messages when the GDB range checker detects a range error,
  837.      but attempt to evaluate the expression anyway.  Evaluating the
  838.      expression may still be impossible for other reasons, such as
  839.      accessing memory that the process does not own (a typical example
  840.      from many Unix systems).
  841.  
  842. `show range'
  843.      Show the current setting of the range checker, and whether or not
  844.      it is being set automatically by GDB.
  845.  
  846. 
  847. File: gdb.info,  Node: Support,  Prev: Checks,  Up: Languages
  848.  
  849. Supported languages
  850. ===================
  851.  
  852.    GDB 4 supports C, C++, and Modula-2.  Some GDB features may be used
  853. in expressions regardless of the language you use: the GDB `@' and `::'
  854. operators, and the `{type}addr' construct (*note Expressions:
  855. Expressions.) can be used with the constructs of any supported language.
  856.  
  857.    The following sections detail to what degree each source language is
  858. supported by GDB.  These sections are not meant to be language
  859. tutorials or references, but serve only as a reference guide to what the
  860. GDB expression parser accepts, and what input and output formats should
  861. look like for different languages.  There are many good books written
  862. on each of these languages; please look to these for a language
  863. reference or tutorial.
  864.  
  865. * Menu:
  866.  
  867. * C::                           C and C++
  868. * Modula-2::                    Modula-2
  869.  
  870. 
  871. File: gdb.info,  Node: C,  Next: Modula-2,  Up: Support
  872.  
  873. C and C++
  874. ---------
  875.  
  876.    Since C and C++ are so closely related, many features of GDB apply
  877. to both languages.  Whenever this is the case, we discuss both languages
  878. together.
  879.  
  880.    The C++ debugging facilities are jointly implemented by the GNU C++
  881. compiler and GDB.  Therefore, to debug your C++ code effectively, you
  882. must compile your C++ programs with the GNU C++ compiler, `g++'.
  883.  
  884.    For best results when debugging C++ programs, use the stabs debugging
  885. format.  You can select that format explicitly with the `g++'
  886. command-line options `-gstabs' or `-gstabs+'.  See *Note Options for
  887. Debugging Your Program or GNU CC: (gcc.info)Debugging Options, for more
  888. information.
  889.  
  890. * Menu:
  891.  
  892. * C Operators::                 C and C++ operators
  893. * C Constants::                 C and C++ constants
  894. * Cplus expressions::           C++ expressions
  895. * C Defaults::                  Default settings for C and C++
  896.  
  897. * C Checks::                    C and C++ type and range checks
  898.  
  899. * Debugging C::                 GDB and C
  900. * Debugging C plus plus::       Special features for C++
  901.  
  902. 
  903. File: gdb.info,  Node: C Operators,  Next: C Constants,  Up: C
  904.  
  905. C and C++ operators
  906. -------------------
  907.  
  908.    Operators must be defined on values of specific types.  For instance,
  909. `+' is defined on numbers, but not on structures.  Operators are often
  910. defined on groups of types.
  911.  
  912.    For the purposes of C and C++, the following definitions hold:
  913.  
  914.    * *Integral types* include `int' with any of its storage-class
  915.      specifiers; `char'; and `enum'.
  916.  
  917.    * *Floating-point types* include `float' and `double'.
  918.  
  919.    * *Pointer types* include all types defined as `(TYPE *)'.
  920.  
  921.    * *Scalar types* include all of the above.
  922.  
  923. The following operators are supported.  They are listed here in order
  924. of increasing precedence:
  925.  
  926. `,'
  927.      The comma or sequencing operator.  Expressions in a
  928.      comma-separated list are evaluated from left to right, with the
  929.      result of the entire expression being the last expression
  930.      evaluated.
  931.  
  932. `='
  933.      Assignment.  The value of an assignment expression is the value
  934.      assigned.  Defined on scalar types.
  935.  
  936. `OP='
  937.      Used in an expression of the form `A OP= B', and translated to
  938.      `A = A OP B'.  `OP=' and `=' have the same precendence.  OP is any
  939.      one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
  940.      `/', `%'.
  941.  
  942. `?:'
  943.      The ternary operator.  `A ? B : C' can be thought of as:  if A
  944.      then B else C.  A should be of an integral type.
  945.  
  946. `||'
  947.      Logical OR.  Defined on integral types.
  948.  
  949. `&&'
  950.      Logical AND.  Defined on integral types.
  951.  
  952. `|'
  953.      Bitwise OR.  Defined on integral types.
  954.  
  955. `^'
  956.      Bitwise exclusive-OR.  Defined on integral types.
  957.  
  958. `&'
  959.      Bitwise AND.  Defined on integral types.
  960.  
  961. `==, !='
  962.      Equality and inequality.  Defined on scalar types.  The value of
  963.      these expressions is 0 for false and non-zero for true.
  964.  
  965. `<, >, <=, >='
  966.      Less than, greater than, less than or equal, greater than or equal.
  967.      Defined on scalar types.  The value of these expressions is 0 for
  968.      false and non-zero for true.
  969.  
  970. `<<, >>'
  971.      left shift, and right shift.  Defined on integral types.
  972.  
  973. `@'
  974.      The GDB "artificial array" operator (*note Expressions:
  975.      Expressions.).
  976.  
  977. `+, -'
  978.      Addition and subtraction.  Defined on integral types,
  979.      floating-point types and pointer types.
  980.  
  981. `*, /, %'
  982.      Multiplication, division, and modulus.  Multiplication and
  983.      division are defined on integral and floating-point types.
  984.      Modulus is defined on integral types.
  985.  
  986. `++, --'
  987.      Increment and decrement.  When appearing before a variable, the
  988.      operation is performed before the variable is used in an
  989.      expression; when appearing after it, the variable's value is used
  990.      before the operation takes place.
  991.  
  992. `*'
  993.      Pointer dereferencing.  Defined on pointer types.  Same precedence
  994.      as `++'.
  995.  
  996. `&'
  997.      Address operator.  Defined on variables.  Same precedence as `++'.
  998.  
  999.      For debugging C++, GDB implements a use of `&' beyond what is
  1000.      allowed in the C++ language itself: you can use `&(&REF)' (or, if
  1001.      you prefer, simply `&&REF') to examine the address where a C++
  1002.      reference variable (declared with `&REF') is stored.
  1003.  
  1004. `-'
  1005.      Negative.  Defined on integral and floating-point types.  Same
  1006.      precedence as `++'.
  1007.  
  1008. `!'
  1009.      Logical negation.  Defined on integral types.  Same precedence as
  1010.      `++'.
  1011.  
  1012. `~'
  1013.      Bitwise complement operator.  Defined on integral types.  Same
  1014.      precedence as `++'.
  1015.  
  1016. `., ->'
  1017.      Structure member, and pointer-to-structure member.  For
  1018.      convenience, GDB regards the two as equivalent, choosing whether
  1019.      to dereference a pointer based on the stored type information.
  1020.      Defined on `struct' and `union' data.
  1021.  
  1022. `[]'
  1023.      Array indexing.  `A[I]' is defined as `*(A+I)'.  Same precedence
  1024.      as `->'.
  1025.  
  1026. `()'
  1027.      Function parameter list.  Same precedence as `->'.
  1028.  
  1029. `::'
  1030.      C++ scope resolution operator.  Defined on `struct', `union', and
  1031.      `class' types.
  1032.  
  1033. `::'
  1034.      Doubled colons also represent the GDB scope operator (*note
  1035.      Expressions: Expressions.).  Same precedence as `::', above.
  1036.  
  1037. 
  1038. File: gdb.info,  Node: C Constants,  Next: Cplus expressions,  Prev: C Operators,  Up: C
  1039.  
  1040. C and C++ constants
  1041. -------------------
  1042.  
  1043.    GDB allows you to express the constants of C and C++ in the
  1044. following ways:
  1045.  
  1046.    * Integer constants are a sequence of digits.  Octal constants are
  1047.      specified by a leading `0' (ie. zero), and hexadecimal constants by
  1048.      a leading `0x' or `0X'.  Constants may also end with a letter `l',
  1049.      specifying that the constant should be treated as a `long' value.
  1050.  
  1051.    * Floating point constants are a sequence of digits, followed by a
  1052.      decimal point, followed by a sequence of digits, and optionally
  1053.      followed by an exponent.  An exponent is of the form:
  1054.      `e[[+]|-]NNN', where NNN is another sequence of digits.  The `+'
  1055.      is optional for positive exponents.
  1056.  
  1057.    * Enumerated constants consist of enumerated identifiers, or their
  1058.      integral equivalents.
  1059.  
  1060.    * Character constants are a single character surrounded by single
  1061.      quotes (`''), or a number--the ordinal value of the corresponding
  1062.      character (usually its ASCII value).  Within quotes, the single
  1063.      character may be represented by a letter or by "escape sequences",
  1064.      which are of the form `\NNN', where NNN is the octal representation
  1065.      of the character's ordinal value; or of the form `\X', where `X'
  1066.      is a predefined special character--for example, `\n' for newline.
  1067.  
  1068.    * String constants are a sequence of character constants surrounded
  1069.      by double quotes (`"').
  1070.  
  1071.    * Pointer constants are an integral value.  You can also write
  1072.      pointers to constants using the C operator `&'.
  1073.  
  1074.    * Array constants are comma-separated lists surrounded by braces `{'
  1075.      and `}'; for example, `{1,2,3}' is a three-element array of
  1076.      integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
  1077.      `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
  1078.  
  1079. 
  1080. File: gdb.info,  Node: Cplus expressions,  Next: C Defaults,  Prev: C Constants,  Up: C
  1081.  
  1082. C++ expressions
  1083. ---------------
  1084.  
  1085.    GDB expression handling has a number of extensions to interpret a
  1086. significant subset of C++ expressions.
  1087.  
  1088.      *Warning:* GDB can only debug C++ code if you compile with the GNU
  1089.      C++ compiler.  Moreover, C++ debugging depends on the use of
  1090.      additional debugging information in the symbol table, and thus
  1091.      requires special support.  GDB has this support *only* with the
  1092.      stabs debug format.  In particular, if your compiler generates
  1093.      a.out, MIPS ECOFF, RS/6000 XCOFF, or ELF with stabs extensions to
  1094.      the symbol table, these facilities are all available.  (With GNU
  1095.      CC, you can use the `-gstabs' option to request stabs debugging
  1096.      extensions explicitly.)  Where the object code format is standard
  1097.      COFF or DWARF in ELF, on the other hand, most of the C++ support
  1098.      in GDB does *not* work.
  1099.  
  1100.   1. Member function calls are allowed; you can use expressions like
  1101.  
  1102.           count = aml->GetOriginal(x, y)
  1103.  
  1104.   2. While a member function is active (in the selected stack frame),
  1105.      your expressions have the same namespace available as the member
  1106.      function; that is, GDB allows implicit references to the class
  1107.      instance pointer `this' following the same rules as C++.
  1108.  
  1109.   3. You can call overloaded functions; GDB resolves the function call
  1110.      to the right definition, with one restriction--you must use
  1111.      arguments of the type required by the function that you want to
  1112.      call.  GDB does not perform conversions requiring constructors or
  1113.      user-defined type operators.
  1114.  
  1115.   4. GDB understands variables declared as C++ references; you can use
  1116.      them in expressions just as you do in C++ source--they are
  1117.      automatically dereferenced.
  1118.  
  1119.      In the parameter list shown when GDB displays a frame, the values
  1120.      of reference variables are not displayed (unlike other variables);
  1121.      this avoids clutter, since references are often used for large
  1122.      structures.  The *address* of a reference variable is always
  1123.      shown, unless you have specified `set print address off'.
  1124.  
  1125.   5. GDB supports the C++ name resolution operator `::'--your
  1126.      expressions can use it just as expressions in your program do.
  1127.      Since one scope may be defined in another, you can use `::'
  1128.      repeatedly if necessary, for example in an expression like
  1129.      `SCOPE1::SCOPE2::NAME'.  GDB also allows resolving name scope by
  1130.      reference to source files, in both C and C++ debugging (*note
  1131.      Program variables: Variables.).
  1132.  
  1133. 
  1134. File: gdb.info,  Node: C Defaults,  Next: C Checks,  Prev: Cplus expressions,  Up: C
  1135.  
  1136. C and C++ defaults
  1137. ------------------
  1138.  
  1139.    If you allow GDB to set type and range checking automatically, they
  1140. both default to `off' whenever the working language changes to C or
  1141. C++.  This happens regardless of whether you, or GDB, selected the
  1142. working language.
  1143.  
  1144.    If you allow GDB to set the language automatically, it sets the
  1145. working language to C or C++ on entering code compiled from a source
  1146. file whose name ends with `.c', `.C', or `.cc'.  *Note Having GDB infer
  1147. the source language: Automatically, for further details.
  1148.  
  1149. 
  1150. File: gdb.info,  Node: C Checks,  Next: Debugging C,  Prev: C Defaults,  Up: C
  1151.  
  1152. C and C++ type and range checks
  1153. -------------------------------
  1154.  
  1155.    By default, when GDB parses C or C++ expressions, type checking is
  1156. not used.  However, if you turn type checking on, GDB considers two
  1157. variables type equivalent if:
  1158.  
  1159.    * The two variables are structured and have the same structure,
  1160.      union, or enumerated tag.
  1161.  
  1162.    * Two two variables have the same type name, or types that have been
  1163.      declared equivalent through `typedef'.
  1164.  
  1165.    Range checking, if turned on, is done on mathematical operations.
  1166. Array indices are not checked, since they are often used to index a
  1167. pointer that is not itself an array.
  1168.  
  1169. 
  1170. File: gdb.info,  Node: Debugging C,  Next: Debugging C plus plus,  Prev: C Checks,  Up: C
  1171.  
  1172. GDB and C
  1173. ---------
  1174.  
  1175.    The `set print union' and `show print union' commands apply to the
  1176. `union' type.  When set to `on', any `union' that is inside a `struct'
  1177. or `class' is also printed.  Otherwise, it appears as `{...}'.
  1178.  
  1179.    The `@' operator aids in the debugging of dynamic arrays, formed
  1180. with pointers and a memory allocation function.  *Note Expressions:
  1181. Expressions.
  1182.  
  1183. 
  1184. File: gdb.info,  Node: Debugging C plus plus,  Prev: Debugging C,  Up: C
  1185.  
  1186. GDB features for C++
  1187. --------------------
  1188.  
  1189.    Some GDB commands are particularly useful with C++, and some are
  1190. designed specifically for use with C++.  Here is a summary:
  1191.  
  1192. `breakpoint menus'
  1193.      When you want a breakpoint in a function whose name is overloaded,
  1194.      GDB breakpoint menus help you specify which function definition
  1195.      you want.  *Note Breakpoint menus: Breakpoint Menus.
  1196.  
  1197. `rbreak REGEX'
  1198.      Setting breakpoints using regular expressions is helpful for
  1199.      setting breakpoints on overloaded functions that are not members
  1200.      of any special classes.  *Note Setting breakpoints: Set Breaks.
  1201.  
  1202. `catch EXCEPTIONS'
  1203. `info catch'
  1204.      Debug C++ exception handling using these commands.  *Note
  1205.      Breakpoints and exceptions: Exception Handling.
  1206.  
  1207. `ptype TYPENAME'
  1208.      Print inheritance relationships as well as other information for
  1209.      type TYPENAME.  *Note Examining the Symbol Table: Symbols.
  1210.  
  1211. `set print demangle'
  1212. `show print demangle'
  1213. `set print asm-demangle'
  1214. `show print asm-demangle'
  1215.      Control whether C++ symbols display in their source form, both when
  1216.      displaying code as C++ source and when displaying disassemblies.
  1217.      *Note Print settings: Print Settings.
  1218.  
  1219. `set print object'
  1220. `show print object'
  1221.      Choose whether to print derived (actual) or declared types of
  1222.      objects.  *Note Print settings: Print Settings.
  1223.  
  1224. `set print vtbl'
  1225. `show print vtbl'
  1226.      Control the format for printing virtual function tables.  *Note
  1227.      Print settings: Print Settings.
  1228.  
  1229. `Overloaded symbol names'
  1230.      You can specify a particular definition of an overloaded symbol,
  1231.      using the same notation that is used to declare such symbols in
  1232.      C++: type `SYMBOL(TYPES)' rather than just SYMBOL.  You can also
  1233.      use the GDB command-line word completion facilities to list the
  1234.      available choices, or to finish the type list for you.  *Note
  1235.      Command completion: Completion, for details on how to do this.
  1236.  
  1237. 
  1238. File: gdb.info,  Node: Modula-2,  Prev: C,  Up: Support
  1239.  
  1240. Modula-2
  1241. --------
  1242.  
  1243.    The extensions made to GDB to support Modula-2 only support output
  1244. from the GNU Modula-2 compiler (which is currently being developed).
  1245. Other Modula-2 compilers are not currently supported, and attempting to
  1246. debug executables produced by them is most likely to give an error as
  1247. GDB reads in the executable's symbol table.
  1248.  
  1249. * Menu:
  1250.  
  1251. * M2 Operators::                Built-in operators
  1252. * Built-In Func/Proc::           Built-in functions and procedures
  1253. * M2 Constants::                Modula-2 constants
  1254. * M2 Defaults::                 Default settings for Modula-2
  1255. * Deviations::                  Deviations from standard Modula-2
  1256. * M2 Checks::                   Modula-2 type and range checks
  1257. * M2 Scope::                    The scope operators `::' and `.'
  1258. * GDB/M2::                      GDB and Modula-2
  1259.  
  1260. 
  1261. File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
  1262.  
  1263. Operators
  1264. ---------
  1265.  
  1266.    Operators must be defined on values of specific types.  For instance,
  1267. `+' is defined on numbers, but not on structures.  Operators are often
  1268. defined on groups of types.  For the purposes of Modula-2, the
  1269. following definitions hold:
  1270.  
  1271.    * *Integral types* consist of `INTEGER', `CARDINAL', and their
  1272.      subranges.
  1273.  
  1274.    * *Character types* consist of `CHAR' and its subranges.
  1275.  
  1276.    * *Floating-point types* consist of `REAL'.
  1277.  
  1278.    * *Pointer types* consist of anything declared as `POINTER TO TYPE'.
  1279.  
  1280.    * *Scalar types* consist of all of the above.
  1281.  
  1282.    * *Set types* consist of `SET' and `BITSET' types.
  1283.  
  1284.    * *Boolean types* consist of `BOOLEAN'.
  1285.  
  1286. The following operators are supported, and appear in order of
  1287. increasing precedence:
  1288.  
  1289. `,'
  1290.      Function argument or array index separator.
  1291.  
  1292. `:='
  1293.      Assignment.  The value of VAR `:=' VALUE is VALUE.
  1294.  
  1295. `<, >'
  1296.      Less than, greater than on integral, floating-point, or enumerated
  1297.      types.
  1298.  
  1299. `<=, >='
  1300.      Less than, greater than, less than or equal to, greater than or
  1301.      equal to on integral, floating-point and enumerated types, or set
  1302.      inclusion on set types.  Same precedence as `<'.
  1303.  
  1304. `=, <>, #'
  1305.      Equality and two ways of expressing inequality, valid on scalar
  1306.      types.  Same precedence as `<'.  In GDB scripts, only `<>' is
  1307.      available for inequality, since `#' conflicts with the script
  1308.      comment character.
  1309.  
  1310. `IN'
  1311.      Set membership.  Defined on set types and the types of their
  1312.      members.  Same precedence as `<'.
  1313.  
  1314. `OR'
  1315.      Boolean disjunction.  Defined on boolean types.
  1316.  
  1317. `AND, &'
  1318.      Boolean conjuction.  Defined on boolean types.
  1319.  
  1320. `@'
  1321.      The GDB "artificial array" operator (*note Expressions:
  1322.      Expressions.).
  1323.  
  1324. `+, -'
  1325.      Addition and subtraction on integral and floating-point types, or
  1326.      union and difference on set types.
  1327.  
  1328. `*'
  1329.      Multiplication on integral and floating-point types, or set
  1330.      intersection on set types.
  1331.  
  1332. `/'
  1333.      Division on floating-point types, or symmetric set difference on
  1334.      set types.  Same precedence as `*'.
  1335.  
  1336. `DIV, MOD'
  1337.      Integer division and remainder.  Defined on integral types.  Same
  1338.      precedence as `*'.
  1339.  
  1340. `-'
  1341.      Negative. Defined on `INTEGER' and `REAL' data.
  1342.  
  1343. `^'
  1344.      Pointer dereferencing.  Defined on pointer types.
  1345.  
  1346. `NOT'
  1347.      Boolean negation.  Defined on boolean types.  Same precedence as
  1348.      `^'.
  1349.  
  1350. `.'
  1351.      `RECORD' field selector.  Defined on `RECORD' data.  Same
  1352.      precedence as `^'.
  1353.  
  1354. `[]'
  1355.      Array indexing.  Defined on `ARRAY' data.  Same precedence as `^'.
  1356.  
  1357. `()'
  1358.      Procedure argument list.  Defined on `PROCEDURE' objects.  Same
  1359.      precedence as `^'.
  1360.  
  1361. `::, .'
  1362.      GDB and Modula-2 scope operators.
  1363.  
  1364.      *Warning:* Sets and their operations are not yet supported, so GDB
  1365.      treats the use of the operator `IN', or the use of operators `+',
  1366.      `-', `*', `/', `=', , `<>', `#', `<=', and `>=' on sets as an
  1367.      error.
  1368.  
  1369.